//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#include "GenRequest.h"

#include "pybind11/pybind11.h"

#include "Constraint.h"
#include "Log.h"

/*!
  \file GenRequestResults
  \brief Module specifically designated to host GenRequest::GetResults method.
*/

using namespace std;

namespace Green {

  void GenPhysicalRegionRequest::GetResults(py::object& rPyObject) const
  {
    rPyObject = py::int_(mBaseAddress);
  }

  void GenVmContextRequest::GetResults(py::object& rPyObject) const
  {
    rPyObject = py::int_(mId);
  }


  void GenSystemCall::GetResults(py::object& rPyObject) const
  {
    py::dict resDict;
    for (auto &item : mSysCallResults)
    {
      resDict[py::cast(item.first)] = py::int_(item.second);
    }
    rPyObject = resDict;
  }

  void GenUpdateHandlerInfo::GetResults(py::object& rPyObject) const
  {
    rPyObject = py::int_(mUpdateHandlerResult);
  }

  void GenLoopRequest::GetResults(py::object& rPyObject) const
  {
    py::tuple result_tuple = py::tuple(2);
    result_tuple[0] = py::int_(mLoopId);
    result_tuple[1] = py::int_(mLoopBackAddress);
    rPyObject = result_tuple;
  }

  void GenLinearBlockRequest::GetResults(py::object& rPyObject) const
  {
    if (mActionType == EGenStateActionType::Push) {
      rPyObject = py::int_(mBlockId);
    }
    else {
      py::tuple result_tuple = py::tuple(3);
      result_tuple[0] = py::int_(mValue);
      result_tuple[1] = py::int_(mBlockEndAddr);
      result_tuple[2] = py::int_(mEmpty);
      rPyObject = result_tuple;
    }
  }

  void GenBntHookRequest::GetResults(py::object& rPyObject) const
  {
    rPyObject = py::int_(mBntId);
  }

  void GenFreePageRequest::GetResults(py::object& rPyObject) const
  {
    auto tuple_num = 3 + mPageNum;
    py::tuple result_tuple = py::tuple(tuple_num);

    result_tuple[0] = mValid;
    result_tuple[1] = mStartAddr;
    result_tuple[2] = mpResolvedRanges->ToSimpleString();
    for (auto i = 0u; i < mPageNum; i ++ )
      result_tuple[3 + i] = mResolvedPageSizes[i];

    rPyObject = result_tuple;
  }

  void GenUpdateVmRequest::GetResults(py::object& rPyObject) const
  {
    rPyObject = py::none();
  }

}
